class Hitbox:
	def __init__(self, rect, properties):
		self.rect = rect
		self.properties = properties
		
	def getOffsetRect(self, pos, flip = False):
		(x,y) = pos
		if flip:
			return (-self.rect[0] + x, self.rect[1] + y, -self.rect[2], self.rect[3])
		else:
			return (self.rect[0] + x, self.rect[1] + y, self.rect[2], self.rect[3])
			
	def __repr__(self):
		return "Hitbox(" + str(self.rect) + "," + str(self.properties)+")"


class Animation:
	def __init__(self, frames, cancelsInto = {}):
		self.frames = frames

		self.hitboxFrames = [ [] for frame in self.frames ]
		self.name = ""
		self.n = 0
		self.ended = False
		self.canExit = False
		self.cancelsInto = cancelsInto

	def setHitboxFrames(self, hitboxFrames):
		if len(hitboxFrames) == len(self.frames):
			self.hitboxFrames = hitboxFrames

	def update(self):
		self.n += 1
		if self.n >= len(self.frames):
			self.ended = True
			self.canExit = True

	def start(self):
		self.n = 0
		self.ended = False
		self.canExit = False

	def getFrame(self):
		return self.frames[min(self.n, len(self.frames)-1)]

	def getHitboxFrame(self):
		return self.hitboxFrames[min(self.n, len(self.frames)-1)]

class LoopingAnimation(Animation):
	def __init__(self, frames):
		Animation.__init__(self ,frames)
		self.canExit = True
		self.ended = True

	def update(self):
		self.n += 1
		if self.n >= len(self.frames):
			self.n = 0

	def start(self):
		self.n = 0
		self.ended = True
		self.canExit = True

class ParryAnimation(Animation):
	def __init__(self, frames):
		Animation.__init__(self, frames)
		self.canExit = True

	def start(self):
		self.n = 0
		self.ended = False
		self.canExit = True
		
class JumpAnimation(Animation):
	def start(self):
		self.n = 0
		self.ended = False
		self.canExit = True

class CrouchAnimation(Animation):
	def __init__(self, frames):
		Animation.__init__(self, frames)
		
	def update(self):
		self.n += 1
		if self.n >= len(self.frames):
			self.n = 3

